package com.Servlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * @auther: cc.ly
 * @date: 2019/1/22/022
 */
@WebServlet(urlPatterns = "/ServletRunTest", asyncSupported = true)
public class ServletAsync extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(req.isAsyncStarted());
        resp.setContentType("text/html");
        PrintWriter writer = resp.getWriter();
        writer.println("servlet begin:" + new Date() + "  " + Thread.currentThread().getName());
        // writer.flush();
        AsyncContext asyncContext = req.getAsyncContext();
        ThreadPoolManager.getInstance().submit(new WorkProcessor(asyncContext));
        writer.println("servlet end:" + new Date() + "  " + Thread.currentThread().getName());
        writer.flush();
    }
}
